const user = require("../models/userDetail")

var express = require('express');
var router = express.Router();

const formidable = require('formidable');

//返回图片
router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, async function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else { 
          try {
            let result = await user.updateOne({
              UUID: fields.UUID
            }, {
              avatar: fields.avatar
            })
            res.json({
              state: true,
              msg: '更换头像成功！'
            })
          } catch(err) {
            console.log(err)
            res.json({
              state: false,
              msg: '更换头像失败！'
            })
          }
        }
    });

});

module.exports = router;